package com.chen.helper.widget;


import android.content.Context;

import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.chen.helper.R;


/**
 * RecycleView 带下拉,上拉
 */

public class RefreshRecycleView extends FrameLayout {
    SwipeRefreshLayout srl;
    RecyclerView rv;


    public RefreshRecycleView(@NonNull Context context) {
        super(context);
        init(context);
    }


    public RefreshRecycleView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initAttr(context, attrs);
        init(context);
    }

    private void init(Context context) {
        View v = View.inflate(context, R.layout.refresh_rv, this);
        srl = v.findViewById(R.id.srl);
        rv = v.findViewById(R.id.rv_cj);
        rv.setHasFixedSize(true);
        rv.setLayoutManager(new LinearLayoutManager(getContext()));
    }

    private void initAttr(Context context, AttributeSet attrs) {
    }


    /**
     * srl 是否作用
     *
     * @param enable
     * @return
     */
    public RefreshRecycleView setSwipeRefresh(boolean enable) {
        srl.setRefreshing(enable);
        return this;
    }

    public RecyclerView getRecyclerView() {
        return rv;
    }

    public SwipeRefreshLayout getSwipeRefreshLayout() {
        return srl;
    }

    public RefreshRecycleView setColorSchemeColors(@ColorInt int... colors) {
        srl.setColorSchemeColors(colors);
        return this;
    }


}
